﻿using log4net;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Ymatou.ServiceCenter;
using Ymatou.User.Dto.Auth;
using YmtAuth.Dto;

namespace YmtAuth.Web.UnitTest
{
    [Category("YmtAuth.Web.UnitTest")]
    [TestFixture]
    public class AuthWebDtoTest
    {
        private static readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        
        [TestFixtureSetUp]
        public void Setup()
        {
            log4net.Config.XmlConfigurator.Configure();
        }

        [Test]
        public void TestLoginAuthRequestDtoGet()
        {
            _logger.Debug("########### TestLoginAuthRequestDtoGet ###########");            

            // http://auth.ymatou.com/json/reply/LoginAuthRequestDto?clientIp=172.16.22.166&loginId=muse&pas=123456&sourceType=main
            LoginAuthRequestDto request = new LoginAuthRequestDto
            {
                ClientIp = "172.16.22.166",
                LoginId = "muse",
                Pas = "123456",
                SourceType = "main"
            };

            ResponseData<LoginAuthResponseDto2> response = ServiceClient.Execute<LoginAuthRequestDto, ResponseData<LoginAuthResponseDto2>>(request);
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success, "登录失败");
        }

        [Test]
        public void TestSSOTokenDtoPost()
        {
            _logger.Debug("########### TestSSOTokenDtoPost ###########");

            // http://auth.ymatou.com/json/reply/SSOTokenDto
            SSOTokenDto request = new SSOTokenDto
            {
                OriginalVal = "0284393A-F5DD-4E8C-94D4-0F4752C22362",
                Token = "1284393A-F5DD-4E8C-94D4-0F4752C22362"
            };

            ResponseData<SignAuthResponseDto2> response = ServiceClient.Execute<SSOTokenDto, ResponseData<SignAuthResponseDto2>>(request);
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success, "登出失败");
        }

        [Test]
        public void TestSignAuthRequestDtoGet()
        {
            _logger.Debug("########### TestSignAuthRequestDtoGet ###########");

            // http://auth.ymatou.com/json/reply/SignAuthRequestDto
            SignAuthRequestDto request = new SignAuthRequestDto
            {
                sClientType = "app",
                DeviceId = "TestAppddddddddddd",
                Token = "18B4A54937ED093B8833818DC34C47C9953934D795FFEAE05C48820745127688683F99F4B214C9790072607F308F1588943CE11DCBF2B618"
            };

            ResponseData<TokenResponseDto> response = ServiceClient.Execute<SignAuthRequestDto, ResponseData<TokenResponseDto>>(request);
            Assert.IsNotNull(response);
            Assert.IsTrue(response.Success, "根据token 获取用户ID失败");
        }

        [Test]
        public void TestDeviceAuthStatusRequestDtoPost()
        {

            _logger.Debug("########### TestDeviceAuthStatusRequestDtoPost ###########");

            // http://auth.ymatou.com/json/reply/DeviceAuthStatusRequestDto
            DeviceAuthStatusRequestDto request = new DeviceAuthStatusRequestDto
            {
                LoginId = "小虎妈妈",
                Password = "123456",
                Ip = "172.16.22.166",
                Success = true,
                Source = "app",
                DeviceId = "firstTime",
                ClientId = "firstTime"
            };

            ResponseData<LoginAuthResponseDto2> response = ServiceClient.Execute<DeviceAuthStatusRequestDto, ResponseData<LoginAuthResponseDto2>>(request);
            Assert.IsNotNull(response);

            Assert.IsTrue(response.Success, "用户设备认证失败");
        }
    }
}
